#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>

int main(int argc, char *argv[]){
    
    int fd;
    if((fd = open("t_dup.txt",O_RDWR|O_CREAT,0666))< 0){
    
        perror("打开文件错误");
    }

    int n_fd = dup(fd); 
    
    if(write(n_fd,"asd",3) != 3){
        
        perror("write error");
    }
    
    printf("%d\n", n_fd);

    close(n_fd);
    
    if(write(fd,"asd",3) != 3){
        
        perror("write2-- error");
    }




    return 0;
}
